package pl.edu.amu.wmi.kino.visualjavafx.model.objects.path;

import pl.edu.amu.wmi.kino.visualjavafx.model.objects.shapes.Shape;
import java.awt.Color;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import pl.edu.amu.wmi.kino.visualjavafx.model.animation.animationTime.Timeline;
import pl.edu.amu.wmi.kino.visualjavafx.model.animation.interpolators.PathInterpolator;
import java.util.ArrayList; 

// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
import pl.edu.amu.wmi.kino.visualjavafx.model.objects.Point;
import pl.edu.amu.wmi.kino.visualjavafx.model.objects.VisualObject;
// #[regen=yes,id=DCE.D680460B-87DD-A733-7A25-EB7E475C9CB1]
// </editor-fold> 

public class Path implements Shape ,java.io.Serializable{

    // Code block for changeListeners support start
    protected PropertyChangeSupport propertySupport= new PropertyChangeSupport(this);
    @Override
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.addPropertyChangeListener(listener);
    }
    @Override
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.removePropertyChangeListener(listener);
    }
    // Code block for changeListeners support end

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.7CEF81AD-79CA-857B-913C-4C80DDFF1873]
    // </editor-fold> 
    private PathInterpolator hPathInterpolator;

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.F97B3773-1FF7-418E-DB28-4BD96DE90213]
    // </editor-fold> 
    private PathInterpolator vPathInterpolator;

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.40E54A21-1431-D147-269A-CFB37EE034F4]
    // </editor-fold> 
    private ArrayList<PathElement> mPathElement;

    private double hPos = 0 ;
    private double vPos = 0 ;
    private double hSize = 0;
    private double vSize = 0;
    private double rotation = 0 ;
    private double vCenterDelta = 0 ;
    private double hCenterDelta = 0 ;
    private double borderWidth = 1;
    private double opacity = 1;
    private double hShear = 0;
    private double vShear = 0;
    private Color borderColor = new Color(0,0,0) ;
    private Color fillColor = new Color(255,255,255) ;
    private boolean visible = true;
    private Timeline timeline = new Timeline();


    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.BEE6B51F-A3CD-D489-137F-B21905D8A175]
    // </editor-fold> 
    public Path () {
    }
    
    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.D346E518-B171-84D1-CE8D-593FE97F5982]
    // </editor-fold> 
    @Override
    public double getHPos () {
        return this.hPos;
    }

    public void addPathElement(PathElement e){
        this.mPathElement.add(e);
        this.normalize();
    }

    public void normalize(){
        double minX=Double.POSITIVE_INFINITY;
        double minY=Double.POSITIVE_INFINITY;
        double maxX=Double.NEGATIVE_INFINITY;
        double maxY=Double.NEGATIVE_INFINITY;

       for(PathElement e : this.mPathElement){
            for(Point p : e.getPoints()){
                if(p.getHPos()<minX)
                minX=p.getHPos();
                if(p.getVPos()<minY)
                minY=p.getVPos();
                if(p.getHPos()>maxX)
                maxX=p.getHPos();
                if(p.getVPos()>maxY)
                maxY=p.getVPos();
            }
       }
       this.setHPos(minX);
       this.setVPos(minY);
       maxX=maxX-minX;
       maxY=maxY-minY;
       this.hSize=maxX;
       this.vSize=maxY;
       for(PathElement e : this.mPathElement){
            for(Point p : e.getPoints()){
                p.setHPos(p.getHPos()-minX);
                p.setHPos(p.getHPos()-minY);
            }
       }

    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.55F1EA7F-074A-EB6F-A661-C79359D12322]
    // </editor-fold> 
    @Override
    public void setHPos (double val) {
        this.hPos=val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.5E133551-E0F8-BDC2-9B68-757E874A5A06]
    // </editor-fold> 
    @Override
    public double getVPos () {
        return this.vPos;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.B4CEB572-3E7A-E03B-2F49-8C29109D97A1]
    // </editor-fold> 
    @Override
    public void setVPos (double val) {
        this.vPos=val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.D0DBDF53-20CD-AE37-50B9-12A53E595511]
    // </editor-fold> 
    @Override
    public double getRotation () {
        return this.rotation;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.E56ACA41-69FB-C115-CC12-D6A1AF196D7D]
    // </editor-fold> 
    @Override
    public void setRotation (double val) {
        this.rotation=val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.64DECBAC-6033-D21A-4115-7F4EC1BA3861]
    // </editor-fold> 
    @Override
    public double getVCenterDelta () {
        return this.vCenterDelta;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.72324A69-0A04-7471-7CDA-1AB8DFD13D92]
    // </editor-fold> 
    @Override
    public void setVCenterDelta (double val) {
        this.vCenterDelta=val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.6C088E20-363F-9865-F87F-F08DFD55D849]
    // </editor-fold> 
    @Override
    public double getHCenterDelta () {
        return this.hCenterDelta;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.E8050440-C204-4261-0E4F-AC2BE4CB5D05]
    // </editor-fold> 
    @Override
    public void setHCenterDelta (double val) {
        this.hCenterDelta=val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.D8ACD8E7-50BF-E863-6786-872C380FEDA3]
    // </editor-fold> 
    @Override
    public double getSizeH () {
        return this.hSize;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.F26123F3-7924-C78A-9E67-FF8675D79467]
    // </editor-fold> 
    @Override
    public void setSizeH (double val) {
        this.hSize=val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.100751E4-5433-826C-92A2-A5F279C375A8]
    // </editor-fold> 
    @Override
    public double getSizeV () {
        return this.vSize;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.FDF723E0-D790-A4ED-447B-B7E580D1815A]
    // </editor-fold> 
    @Override
    public void setSizeV (double val) {
        this.vSize=val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.AE3D92A3-0CB2-D3E9-B7C5-36AE4B9CFE0B]
    // </editor-fold> 
    public PathInterpolator getHPathInterpolator () {
        return hPathInterpolator;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.87260923-77CE-A8B1-BEBA-E1791BA14072]
    // </editor-fold> 
    public PathInterpolator getVPathInterpolator () {
        return vPathInterpolator;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.CED5FE89-D411-53C4-E7CF-DEEE2F7A1BD0]
    // </editor-fold> 
    @Override
    public double getBorderWidth () {
        return this.borderWidth;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.D0238D9F-7B52-8C1F-BBF4-31683F584CCC]
    // </editor-fold> 
    @Override
    public void setBorderWidth (double val) {
        this.borderWidth=val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.3803F774-C44C-9152-AA76-4B98031A0D34]
    // </editor-fold> 
    @Override
    public double getOpacity () {
        return this.opacity;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.A840D402-CDF5-ABD6-B53E-FB0C0EAC6D61]
    // </editor-fold> 
    @Override
    public void setOpacity (double val) {
        this.opacity=val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.5B696134-82B4-F09C-81EF-9CBFBC01EB6D]
    // </editor-fold> 
    public ArrayList<PathElement> getPathElement () {
        return mPathElement;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.844A4620-D8BE-CDD3-D0E7-17DCC7796852]
    // </editor-fold> 
    public void setPathElement (ArrayList<PathElement> val) {
        this.mPathElement = val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.4BB4E7CB-161D-E90B-94A0-03786FFC243E]
    // </editor-fold> 
    @Override
    public double getHShear () {
        return this.hShear;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.84C838DB-BC42-BC9D-B535-07783FFE598B]
    // </editor-fold> 
    @Override
    public void setHShear (double val) {
        this.hShear=val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.6CDB33EC-D72D-8E65-942F-51F9A9D3466D]
    // </editor-fold> 
    @Override
    public double getVShear () {
        return this.vShear;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.DC170BA1-A34E-D456-0015-B44A0E92B4FD]
    // </editor-fold> 
    @Override
    public void setVShear (double val) {
        this.vShear=val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.29AAE791-AA73-C7BC-7EDA-C89C7BCB3235]
    // </editor-fold> 
    @Override
    public Path toPath () {
        return null;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.0D0F15D6-1F8A-BC43-D2B1-4024F64ECBCC]
    // </editor-fold> 
    @Override
    public void setVisibility (boolean val) {
        this.visible=val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.63893132-14DE-7D51-3DD3-ACF3AC31F36E]
    // </editor-fold> 
    @Override
    public boolean getVisibility () {
        return this.visible;
    }

    @Override
    public Timeline getTimeline() {
        return this.timeline;
    }

    @Override
    public Color getBorderColor() {
        return this.borderColor;
    }

    @Override
    public void setBorderColor(Color val) {
       this.borderColor=val;
    }

    @Override
    public Color getFillColor() {
        return this.fillColor;
    }

    @Override
    public void setFillColor(Color val) {
        this.fillColor=val;
    }

    @Override
    public VisualObject shallowClone(){
        Path res = new Path();
        res.hPos=this.hPos;
        res.vPos=this.vPos;
        res.rotation=this.rotation;
        res.vCenterDelta=this.vCenterDelta;
        res.hCenterDelta=this.hCenterDelta;
        res.opacity=this.opacity;
        res.hShear=this.hShear;
        res.vShear=this.vShear;
        res.borderColor=new Color(this.borderColor.getRGB());
        res.fillColor=new Color(this.fillColor.getRGB());
        res.visible=this.visible;
        for(PathElement p : this.mPathElement){
            res.mPathElement.add(p.shallowClone());
        }
        return res;
    }

}

